
from  abc import ABC, abstractmethod

class ApiModel(ABC):
    def __init__(self,
                 api_key="sk-bbeb8854532e44ac8e1c21246b181964",
                 base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1",
                 model='qwen-plus',
                 stream=False,
                 thinking=False):
        self.api_key = api_key
        self.base_url = base_url
        self.model = model
        self.stream = stream
        self.thinking = thinking

    # 输出Token数量
    @abstractmethod
    def print_token_count(self, token_usage):
        pass

    # 以非流式输出答案
    @abstractmethod
    def print_text_not_stream(self, resp) -> str:
        pass

    # 以流式方式输出答案
    @abstractmethod
    def print_text_stream(self, resp) -> str:
        pass

    # 对话
    @abstractmethod
    def chat(self, messages) -> str:
        pass

    # 输出文本答案
    def print_text_answer(self, resp) -> str:
        if self.stream:
            return self.print_text_stream(resp)
        else:
            return self.print_text_not_stream(resp)